﻿using System;
using Besture.Bll;
using Besture.Common;
using Besture.UI.Admin.Master;
using Besture.UI.ClassHelper;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.Data;

namespace Besture.UI.Admin.LabelManage
{
    public partial class LabelList : BasePage
    {
        #region 页面加载

        /// <summary>
        /// 初始化页面
        /// </summary>
        protected override void InitialLoad()
        {
            BindData();
            AspxGridViewHelper.InitAspxGridView(grid);

            ((ConfigAdmin) this.Master).Title = "数据源管理";
        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {
            BindData();
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        public void BindData()
        {
            SqlDac dac = new SqlDac();
            grid.DataSource = dac.GetDataTable();
            grid.DataBind();
        }

        /// <summary>
        /// AspxGridView回发事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grid_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            if (e.Parameters == "Refresh")
                grid.DataBind();
        }

        #endregion

        #region 删除数据

        /// <summary>
        /// 删除单条数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grid_RowDeleting(object sender, ASPxDataDeletingEventArgs e)
        {
            e.Cancel = true;
            int ID = Convert.ToInt32(e.Keys[0]);
            SqlDac SqlDac = new SqlDac();
            SqlDac.Delete(ID);
            BindData();
        }

        /// <summary>
        /// 删除选中数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void DeleteSelect()
        {
            string ids = AspxGridViewHelper.GetCheckID(grid);
            if (string.IsNullOrEmpty(ids))
            {
                return;
            }
            SqlDac SqlDac = new SqlDac();
            SqlDac.DeleteList(ids);
            BindData();
        }

        #endregion

        #region 转向添加页面

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="eventArgs"></param>
        protected void btnAdd_Click(object obj, EventArgs eventArgs)
        {
            RedirectUrl("LabelSet.aspx");
        }

        #endregion

    }
}